import 'package:constellation/global.dart';
import 'package:flutter/material.dart';

class Avatar extends StatefulWidget {
  Avatar({Key key, this.sex, this.index, this.size, this.shadow = true})
      : super(key: key);
  final int sex;
  final index;
  final double size;
  final bool shadow;

  @override
  _AvatarState createState() => _AvatarState();
}

class _AvatarState extends State<Avatar> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    var colors = [
      Color(0xFFfff6f6),
      Color(0xFFffc5c5),
    ];
    switch (widget.sex) {
      case 0:
        colors = [
          Color(0xFFfff6f6),
          Color(0xFFffc5c5),
        ];
        break;
      case 1:
        colors = [
          Color(0xFFf3f9ff),
          Color(0xFFd1ebfd),
        ];
        break;
      case 2:
        colors = [
          Global.mainColor.withOpacity(0.2),
          Global.mainDarkColor,
        ];
        break;
      default:
    }
    return Container(
      width: widget.size ?? 80,
      height: widget.size ?? 80,
      padding: EdgeInsets.all(7),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: colors,
        ),
        borderRadius: BorderRadius.circular(100),
        boxShadow: [
          BoxShadow(
            color: Color(0xFF000000).withOpacity(widget.shadow ? 0.1 : 0),
            offset: Offset(0, 15),
            blurRadius: 15,
            spreadRadius: 1,
          )
        ],
      ),
      child: Image.asset('assets/images/${widget.index.toString()}.png'),
    );
  }
}
